<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="<c:url value='/js/plug/area/load_area.js'/>"></script>

<div id="cc_buyers" class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'采购商管理',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>中文名称</span></td>
				<td class="screen-n">
					<input type="text" id="s_chsName" class="screen-input" onkeydown="pms.kd13('initBuyers')">
				</td>
				<td class="screen-n"><span>地区刷选</span></td>
				<td class="screen-n">
						<div id="loc" >
     		                  <select name="province" id="province" >
     		                     <option value="0">选择省</option>
     		                  </select>   
     		                  <select name="city" id="city" >
     		                     <option value="0">选择市</option>
     		                  </select>   
     		                  <select name="district" id="district" >
     		                     <option value="0">选择地区</option>
     		                  </select>
     	                  </div>
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initBuyers()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>  
<script>
var toolbar = [{
	text:'新增登录账号',
    iconCls:'icon-add',
    handler:function(){
    	openUserAddWindow();
    }
},{
	text:'开启账号',
    iconCls:'icon-add',
    handler:function(){
    	openBuyerAddWindow();
    }
},{
	text:'锁定账号',
    iconCls:'icon-add',
    handler:function(){
    	 var r = checkSelect();
    	 if(r){
			 
         }
        	 
    }
},{
	text:'删除账号',
    iconCls:'icon-add',
    handler:function(){
    	openBuyerAddWindow();
    }
}];

$(function(){
	$("#loc").LocationSelect({
		data:"<c:url value='/js/plug/area/areas.json' />"
	});
});
var buyersTable;
function initBuyers(){
	buyersTable = $('#tableGrid').pDataGrid({
		toolbar:toolbar,
		 columns:[[
					  {field:'ck',checkbox:true},
		              {field:'loginName',title:'登录名',align:'center'},
		              {field:'isValid',title:'状态',align:'center',formatter:function(value,row){
						if(value==0){
							return '未审核';
						}else if(value==1){
							return '已审核';
						}else if(value==2){
							return '锁定';
						} 
			          }},
		              {field:'userName',title:'用户名称',align:'center'},
		              {field:'userType',title:'用户类型',align:'center'},
		              {field:'userType',title:'单位名称',align:'center'},
		              {field:'email',title:'邮箱',align:'center'},
		              {field:'mobilePhone',title:'电话',align:'center'},
		              {field:'address',title:'地址',align:'center'},
		              {field:'loginAmount',title:'登录次数',align:'center'},
		              {field:'begoreLoginTime',title:'前一次登录时间',align:'center'},
		              {field:'lastLoginTime',title:'最后登录时间',align:'center'},
		              {field:'ac',title:'操作',align:'center',formatter:function(value,row){
			              return '<a href="#" >[修改]</a>';
			          }}
		          ]],
		    url:'<c:url value="/user/searchPageUser.do" />',  
		    pagination:true,//分页控件
		    pageSize:30,
		    rownumbers:true,
		    singleSelect:false,
		    queryParams:{
				"chsName":$('#s_chsName').val(), 
				"areaCode":$("#s_areaCode").val(),
		    },
		    onDblClickRow:function(index,row){
		    	openUserUpdateWindow(row.userId);
			}
		    
	}); 
}
initBuyers();
//修改 
function openUserUpdateWindow(id){
	 	var param = {"userId":id};
		$.pmsDialog({
			id:'w_user_update',
    		title:'登录账号修改',
    		method:'post',
    		href:'<c:url value="/views/jsp/customer/user/user_update.jsp"/>',
    		width:700,
    		params:param
    	});
}
//新增
function openUserAddWindow(){
	$.pmsDialog({
		id:'w_user_add',
		title:'登录账号新增',
		method:'post',
		href:'<c:url value="/views/jsp/customer/user/user_add.jsp"/>',
		width:700
	});
}

//检查选中
function checkSelect(){
	var  selU = buyersTable.getCheckedData();
	if(selU==null || selU.length==0){
		alertWarning("请选择要操作的行!");
		return false;
	}else{
		return selU
	}
}
//删除用户
function deleteUsers(code,i){
	if(confirm("确定删除?")){
		var param = {"buyerCode":code};
		$.pmsAjax({
			url:'<c:url value="/buyers/deleteBuyer.do"/>',
			data:param,
			success:function(data){
				if(data.resultCode=="200"){
					alertShow("删除成功");
					buyersTable.removeRow(i);
				}else{
					alertError(data.resultMessage);
				}
			}
		});
	}
}

</script>
